package learn_250211;

public class Insert {
    public static void main(String[] args){
        int[] a = {3,4,1,2,5};
        insert_sort(a);
        for (int i : a) {
            System.out.print(i + " ");
        }
    }
    private static void insert_sort(int[] a ){
        for (int j =1 ;j<a.length;j++){
            int i = j-1;
            int tmp = a[j];
            boolean swap = false;
            while (i>=0 && tmp<a[i]){
                a[i+1] = a[i];
                i = i-1;
            }
            //这个位置容易出错
                a[i+1] = tmp;

        }
    }

}
